<script lang="ts" setup>
import { computed, h } from 'vue';

import { DICT_TYPE } from '@vben/constants';
import { formatDate } from '@vben/utils';

import { DescriptionChange } from '#/components/description-change';
import DictTag from '#/components/dict-tag/dict-tag.vue';
import { DictBadge } from '#/components/dict-badge';

interface DescriptionItemSchema {
  label: string;
  field: string;
  span?: number;
  render?: (val: any) => any;
}

const props = defineProps<{ data?: any }>();
const formData = computed(() => props.data || {});

function formatDateSafe(
  date: null | string | undefined,
  format = 'YYYY-MM-DD',
) {
  if (!date) return '';
  const d = new Date(date);
  return Number.isNaN(d.getTime()) ? '' : formatDate(d, format);
}

/** 劳务所得情况 Schema */
const laborIncomeSchema = computed<DescriptionItemSchema[]>(() => [
  { label: '讲学收入', field: 'lectureFee', span: 12 },
  { label: '写作收入', field: 'writingFee', span: 12 },
  { label: '咨询收入', field: 'consultingFee', span: 12 },
  { label: '审稿收入', field: 'reviewFee', span: 12 },
  { label: '书画收入', field: 'paintingFee', span: 12 },
  { label: '其他收入', field: 'otherFee', span: 12 },
  { label: '合计收入', field: 'totalAmount', span: 12 },
  {
    label: '年度',
    field: 'year',
    render: (val) => formatDate(val, 'YYYY'),
    span: 12,
  },
  {
    label: '状态',
    field: 'status',
    render: (val) => h(DictTag, { type: DICT_TYPE.COMMON_STATUS, value: val }),
    span: 12,
  },
  {
    label: '创建时间',
    field: 'createTime',
    render: formatDateSafe,
    span: 12,
  },
  {
    label: '更新时间',
    field: 'updateTime',
    render: formatDateSafe,
    span: 12,
  },
]);
</script>

<template>
  <DescriptionChange
    v-if="formData"
    :info="formData"
    :schema="laborIncomeSchema"
    :change-list="formData.changeContent?.fieldChanges || []"
    :highlight-mode="formData.highlightMode"
    :change-type="formData.changeType"
    :label-width="120"
  />
</template>
